from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-23 14:03:03.774939
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 23, Nov, 2022
Time: 14:03:10
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.0295
Nobs: 849.000 HQIC: -51.3398
Log likelihood: 11123.4 FPE: 4.16644e-23
AIC: -51.5324 Det(Omega_mle): 3.74969e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299095 0.050385 5.936 0.000
L1.Burgenland 0.109667 0.034631 3.167 0.002
L1.Kärnten -0.106133 0.018449 -5.753 0.000
L1.Niederösterreich 0.210596 0.072405 2.909 0.004
L1.Oberösterreich 0.100566 0.068825 1.461 0.144
L1.Salzburg 0.251754 0.036717 6.857 0.000
L1.Steiermark 0.037231 0.048149 0.773 0.439
L1.Tirol 0.107497 0.039033 2.754 0.006
L1.Vorarlberg -0.060139 0.033640 -1.788 0.074
L1.Wien 0.054097 0.061506 0.880 0.379
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067755 0.103917 0.652 0.514
L1.Burgenland -0.030257 0.071424 -0.424 0.672
L1.Kärnten 0.047835 0.038051 1.257 0.209
L1.Niederösterreich -0.172949 0.149332 -1.158 0.247
L1.Oberösterreich 0.377810 0.141949 2.662 0.008
L1.Salzburg 0.288445 0.075726 3.809 0.000
L1.Steiermark 0.108158 0.099306 1.089 0.276
L1.Tirol 0.316032 0.080505 3.926 0.000
L1.Vorarlberg 0.023203 0.069380 0.334 0.738
L1.Wien -0.019622 0.126854 -0.155 0.877
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197616 0.026087 7.575 0.000
L1.Burgenland 0.092521 0.017930 5.160 0.000
L1.Kärnten -0.008708 0.009552 -0.912 0.362
L1.Niederösterreich 0.268479 0.037488 7.162 0.000
L1.Oberösterreich 0.114889 0.035635 3.224 0.001
L1.Salzburg 0.052690 0.019010 2.772 0.006
L1.Steiermark 0.016607 0.024930 0.666 0.505
L1.Tirol 0.098589 0.020210 4.878 0.000
L1.Vorarlberg 0.056044 0.017417 3.218 0.001
L1.Wien 0.112316 0.031845 3.527 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104845 0.026753 3.919 0.000
L1.Burgenland 0.047395 0.018388 2.578 0.010
L1.Kärnten -0.017243 0.009796 -1.760 0.078
L1.Niederösterreich 0.197111 0.038445 5.127 0.000
L1.Oberösterreich 0.279156 0.036544 7.639 0.000
L1.Salzburg 0.120153 0.019495 6.163 0.000
L1.Steiermark 0.101764 0.025566 3.980 0.000
L1.Tirol 0.123533 0.020726 5.960 0.000
L1.Vorarlberg 0.069093 0.017862 3.868 0.000
L1.Wien -0.026555 0.032658 -0.813 0.416
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130803 0.048455 2.699 0.007
L1.Burgenland -0.049309 0.033304 -1.481 0.139
L1.Kärnten -0.039546 0.017742 -2.229 0.026
L1.Niederösterreich 0.166832 0.069631 2.396 0.017
L1.Oberösterreich 0.141551 0.066189 2.139 0.032
L1.Salzburg 0.285001 0.035310 8.071 0.000
L1.Steiermark 0.032407 0.046305 0.700 0.484
L1.Tirol 0.163084 0.037538 4.344 0.000
L1.Vorarlberg 0.103326 0.032351 3.194 0.001
L1.Wien 0.067451 0.059150 1.140 0.254
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058565 0.038359 1.527 0.127
L1.Burgenland 0.042511 0.026365 1.612 0.107
L1.Kärnten 0.049752 0.014046 3.542 0.000
L1.Niederösterreich 0.227589 0.055123 4.129 0.000
L1.Oberösterreich 0.271847 0.052398 5.188 0.000
L1.Salzburg 0.058143 0.027953 2.080 0.038
L1.Steiermark -0.006801 0.036657 -0.186 0.853
L1.Tirol 0.156258 0.029717 5.258 0.000
L1.Vorarlberg 0.068300 0.025611 2.667 0.008
L1.Wien 0.074391 0.046826 1.589 0.112
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185289 0.045916 4.035 0.000
L1.Burgenland -0.004525 0.031559 -0.143 0.886
L1.Kärnten -0.060925 0.016813 -3.624 0.000
L1.Niederösterreich -0.086772 0.065982 -1.315 0.188
L1.Oberösterreich 0.192301 0.062720 3.066 0.002
L1.Salzburg 0.059578 0.033460 1.781 0.075
L1.Steiermark 0.225814 0.043878 5.146 0.000
L1.Tirol 0.494977 0.035571 13.915 0.000
L1.Vorarlberg 0.047556 0.030656 1.551 0.121
L1.Wien -0.051288 0.056050 -0.915 0.360
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158676 0.052315 3.033 0.002
L1.Burgenland -0.009182 0.035957 -0.255 0.798
L1.Kärnten 0.064761 0.019156 3.381 0.001
L1.Niederösterreich 0.202603 0.075178 2.695 0.007
L1.Oberösterreich -0.066830 0.071461 -0.935 0.350
L1.Salzburg 0.222372 0.038123 5.833 0.000
L1.Steiermark 0.113465 0.049993 2.270 0.023
L1.Tirol 0.084172 0.040528 2.077 0.038
L1.Vorarlberg 0.122120 0.034928 3.496 0.000
L1.Wien 0.109632 0.063862 1.717 0.086
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356849 0.030847 11.568 0.000
L1.Burgenland 0.008687 0.021202 0.410 0.682
L1.Kärnten -0.024711 0.011295 -2.188 0.029
L1.Niederösterreich 0.228293 0.044328 5.150 0.000
L1.Oberösterreich 0.157462 0.042136 3.737 0.000
L1.Salzburg 0.053151 0.022479 2.365 0.018
L1.Steiermark -0.018319 0.029478 -0.621 0.534
L1.Tirol 0.117648 0.023897 4.923 0.000
L1.Vorarlberg 0.071919 0.020595 3.492 0.000
L1.Wien 0.050369 0.037655 1.338 0.181
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043896 0.161131 0.192459 0.165373 0.131997 0.124399 0.070065 0.231140
Kärnten 0.043896 1.000000 0.002127 0.131617 0.044837 0.099390 0.427719 -0.050605 0.102130
Niederösterreich 0.161131 0.002127 1.000000 0.345186 0.166266 0.311002 0.127890 0.192264 0.341402
Oberösterreich 0.192459 0.131617 0.345186 1.000000 0.235628 0.340600 0.177790 0.180111 0.275498
Salzburg 0.165373 0.044837 0.166266 0.235628 1.000000 0.152880 0.145339 0.152900 0.139914
Steiermark 0.131997 0.099390 0.311002 0.340600 0.152880 1.000000 0.163109 0.148346 0.092502
Tirol 0.124399 0.427719 0.127890 0.177790 0.145339 0.163109 1.000000 0.122092 0.164240
Vorarlberg 0.070065 -0.050605 0.192264 0.180111 0.152900 0.148346 0.122092 1.000000 0.019922
Wien 0.231140 0.102130 0.341402 0.275498 0.139914 0.092502 0.164240 0.019922 1.000000